/**
 * @Description: 消息设置
 * @author 阮荣强
 * @date 2019/12/23
 */
import {Card, Checkbox, Form, Typography,} from 'antd';
import React, {Component, Fragment} from 'react';
import {getWebPath} from "../../../utils/request";
import uiUtils from "../../../utils/uiUtils";
import {requestPromise} from '@/utils/request';
import {formatMessage, FormattedMessage} from 'umi/locale';

const {Title} = Typography;
const FormItem = Form.Item;

@Form.create()
class WebMessageSetting extends Component {
  constructor(props) {
    super(props);
    this.state = {
      messageReminders: ["website"],
    };

    this.getMsgSettting();
  }

  messageReminderChange = (value) => {
    const messageReminders = value || [];

    requestPromise(`${getWebPath()}sys/user/msg/savemsgsetting`, {
      method: 'POST',
      body: messageReminders,
    }).then(res => {
      if (res && res.code === 0) {
        uiUtils.showMessage(
          formatMessage({id: 'ours.curd.show-alert.operate-success'}),
          'success'
        );
      }
    });
  };

  getMsgSettting = () => {
    requestPromise(`${getWebPath()}sys/user/msg/getMsgSetting`, {
      method: 'GET',
    }).then(res => {
      if (res && res.code === 0) {
      }
    });
  };

  render() {
    const style = {
      style: {
        marginLeft: 10,
        marginTop: 10,
      },
    };

    const ItemLayout = {
      labelCol: {span: 3},
      wrapperCol: {span: 20}, //5+19=24,少一个栅格
    };
    const formItemLayout = {
      labelCol: {span: 3},
      wrapperCol: {span: 21}, //5+19=24,少一个栅格
    };
    const colSpanLayout = {md: 24, sm: 24}; //每一col跨?列
    const rowGutterPxLayout = {md: 24, sm: 24}; //col之间的间隔?px
    const {
      form: {getFieldDecorator},
    } = this.props;

    console.log(this.props.form.getFieldsValue());

    return (
      <Fragment>
        <Card
          bordered
          size="small"
          bodyStyle={{paddingBottom: 10}}
          style={{marginBottom: 20}}
        >
          <h3>消息提醒方式</h3>
          <Form layout="horizontal" {...formItemLayout}>
            <FormItem {...formItemLayout}>
              {getFieldDecorator('messageReminders', {
                initialValue: this.state.messageReminders,
                rules: [],
              })(
                <Checkbox.Group style={{width: '100%'}} onChange={this.messageReminderChange}>
                  <Checkbox value="sms">短信</Checkbox>
                  <Checkbox value="email">邮件</Checkbox>
                  <Checkbox value="website">站内信</Checkbox>
                  <Checkbox value="wemp">微信号</Checkbox>
                </Checkbox.Group>
              )}
            </FormItem>
          </Form>
        </Card>
      </Fragment>
    );
  }
}

export default WebMessageSetting;
